// pages/visionDifference/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    txtHeight:0,
    txtTop1:0,
    txtTop2:0,
    scroll1:false,
    scroll1:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const query = wx.createSelectorQuery()
    query.select('.txt-content1').boundingClientRect((res)=>{
      /**height盒子高度 top盒子距离顶部高度*/
      this.setData({
        txtHeight:res.height,
        txtTop1:res.top,
      })
    })
    query.select('.txt-content2').boundingClientRect((res)=>{
      /**height盒子高度 top盒子距离顶部高度*/
      this.setData({
        txtTop2:res.top
      })
    })
    query.exec()
    // query.selectViewport().scrollOffset(function(res){
    //   console.log(res);
    //   /**scrollHeight 距离顶部距离*/
    // })
  },
  scroll(e){
    console.log(1);
    /**
     * txtHeight
     * txtTop1
     * txtTop2
     */
    /**scrollHeight scrollTop*/
    /**scrollTop> (txtTop1+txtHeight)/2
     * txtTop1+txtHeight+(txtTop1+txtHeight)/2
    */
    const txtScrollHeight = this.data.txtTop1+this.data.txtHeight
    const {scrollHeight,scrollTop} = e.detail
    const step = Math.floor(scrollTop / scrollHeight)
    console.log(this.data.txtTop2-txtScrollHeight/2);
    // console.log(this.data.txtTop2-this.data.txtTop1);
    console.log(scrollTop);
    if(scrollTop>txtScrollHeight/2 && scrollTop<txtScrollHeight){
      this.setData({
        scroll1:true
      })
    }else if(scrollTop>this.data.txtTop2-txtScrollHeight/2){
      this.setData({
        scroll2:true
      })
    }else if(scrollTop==(0||scrollHeight)){
      this.setData({
        scroll2:false,
        scroll2:false
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})